<template>
    <h2>登录</h2>
    <table border="1">
        <tr>
            <td>名称</td>
            <td>
                <input type="text" v-model="name" placeholder="请输入名称"/>
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="pwd" placeholder="请输入密码"/>
            </td>
        </tr>
        <tr>
            <input type="button" value="登录" @click="Login"/>
        </tr>
    </table>
</template>
<script setup lang="ts">
    import {ref,onMounted} from 'vue';
    import axios from 'axios';
    import {useCounterStore} from '../stores/counter.ts'
    import {useRoute,useRouter} from 'vue-router';
    const route=useRoute();
    const router=useRouter();

    const name=ref("");
    const pwd=ref("");
    const Counter=useCounterStore();

    //登录
    const Login=()=>{
        axios.get("https://localhost:7038/api/User/Login",{
            params:{
                name:name.value,
                pwd:pwd.value
            }
        })
        .then(res=>{
            if(res.data==""){
                alert('登录失败');
                
            }
            else{
                alert('登录成功');
                console.log(res.data);
                Counter.UserName=res.data.name;
                console.log(Counter.UserName);
                router.push({
                    name:"AddRoomType"
                })
            }
        })
        .catch(err=>{
            console.log(err);
        })
    }

</script>
